cmake_minimum_required(VERSION 3.15)
project(b64 LANGUAGES C CXX)

file(GLOB HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/include/b64/*.h")
add_library(${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/src/src/cdecode.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/src/cencode.c" ${HEADER_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/include")
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES}" WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
install(TARGETS ${PROJECT_NAME}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/b64"
)

set(BASE64_APP base64)
add_executable(${BASE64_APP} "${CMAKE_CURRENT_SOURCE_DIR}/src/base64/base64.cc" ${HEADER_FILES})
target_link_libraries(${BASE64_APP} PRIVATE ${PROJECT_NAME})
target_include_directories(${BASE64_APP} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/include")
target_compile_definitions(${BASE64_APP} PRIVATE BUFFERSIZE=16777216)
set_target_properties(${BASE64_APP} PROPERTIES LINKER_LANGUAGE CXX)
install(TARGETS ${BASE64_APP}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
